package com.ewanghuiju.app.presenter.pintuan;

import com.ewanghuiju.app.base.RxPresenter;
import com.ewanghuiju.app.base.contract.pintuan.PintuanHotContract;
import com.ewanghuiju.app.model.DataManager;
import com.ewanghuiju.app.model.bean.response.PintuanShopListResponBean;
import com.ewanghuiju.app.model.http.response.Optional;
import com.ewanghuiju.app.util.RxUtil;
import com.ewanghuiju.app.widget.CommonSubscriber;

import java.util.List;

import javax.inject.Inject;

/**
 * @author sj  qq:751943509
 * @class describe
 * @time 2020/2/16
 */
public class PintuanHotPresenter extends RxPresenter<PintuanHotContract.View> implements PintuanHotContract.Presenter {

    private DataManager mDataManager;

    @Inject
    public PintuanHotPresenter(DataManager mDataManager) {
        this.mDataManager = mDataManager;
    }

    @Override
    public void getData(int type, int classifyId, int page, int spe_price, int sales, int people_number) {
        if (type == 1) {
            addSubscribe(mDataManager.getPtihotGoodsList(page, spe_price == 0 ? "" : spe_price + "", sales == 0 ? "" : sales + "", people_number == 0 ? "" : people_number + "")
                            .compose(RxUtil.rxSchedulerHelper())
                            .compose(RxUtil.handleMyResultCannull())
                            .subscribeWith(new CommonSubscriber<Optional<List<PintuanShopListResponBean>>>(mView) {
                                @Override
                                public void onNext(Optional<List<PintuanShopListResponBean>> optional) {
                                    if (mView != null)
                                        mView.showContent(optional.getIncludeNull());
                                }

                                @Override
                                public void onError(Throwable e) {
                                    super.onError(e);
                                    if (mView != null)
                                        mView.showContentError();
//                        if (e instanceof ApiException) {
//                        mView.showLoginResponseMsg(((ApiException) e).getCode(), e.getMessage());
//                        } else {
//                        }
                                }
                            })
            );
        } else if (type == 2) {
            //根据二级 分类
            addSubscribe(mDataManager.getPticateGoodsList(page, classifyId + "", spe_price == 0 ? "" : spe_price + "", sales == 0 ? "" : sales + "", people_number == 0 ? "" : people_number + "")
                            .compose(RxUtil.rxSchedulerHelper())
                            .compose(RxUtil.handleMyResultCannull())
                            .subscribeWith(new CommonSubscriber<Optional<List<PintuanShopListResponBean>>>(mView) {
                                @Override
                                public void onNext(Optional<List<PintuanShopListResponBean>> optional) {
                                    if (mView != null)
                                        mView.showContent(optional.getIncludeNull());
                                }

                                @Override
                                public void onError(Throwable e) {
                                    super.onError(e);
                                    if (mView != null)
                                        mView.showContentError();
//                        if (e instanceof ApiException) {
//                        mView.showLoginResponseMsg(((ApiException) e).getCode(), e.getMessage());
//                        } else {
//                        }
                                }
                            })
            );
        } else if (type == 3) {
            //根据一级 分类
            addSubscribe(mDataManager.getPticateOneGoodsList(page, classifyId + "", spe_price == 0 ? "" : spe_price + "", sales == 0 ? "" : sales + "", people_number == 0 ? "" : people_number + "")
                    .compose(RxUtil.rxSchedulerHelper())
                    .compose(RxUtil.handleMyResultCannull())
                    .subscribeWith(new CommonSubscriber<Optional<List<PintuanShopListResponBean>>>(mView) {
                        @Override
                        public void onNext(Optional<List<PintuanShopListResponBean>> optional) {
                            if (mView != null)
                                mView.showContent(optional.getIncludeNull());
                        }

                        @Override
                        public void onError(Throwable e) {
                            super.onError(e);
                            if (mView != null)
                                mView.showContentError();
                        }
                    })
            );
        }

    }
}
